
#ifndef GUI_ASSETS_H__
#define GUI_ASSETS_H__

#include <stdint.h> 
#include <string.h> 

#include "xgui_config.h"
#include "gui_hook.h"

//#define PIC_LIB_START_ADDR          (0xA00000)
//#define PIC_LIB_END_ADDR            (0x9FFFFF)

#define GUI_ASSET_HEADER_MAGIC       0x5249// FM
#define GUI_ASSET_HEADER_VALID       0xA1

#define PIC_LIB_INFO_SIZE           (12)

typedef struct
{
    uint16_t magic;
    uint16_t version;
    uint32_t size;
    uint32_t crc32;
    uint8_t valid;
    uint8_t name[16];
    uint8_t datetime[14];
    uint8_t reserved[5];
}gui_asset_header_t;


typedef struct{
    uint8_t no;
    uint8_t type;
    uint8_t count;
    uint8_t bitcount;

    uint16_t w;
    uint16_t h;
    uint32_t address; 
}gui_assets_image_t;

//typedef struct{
//    uint8_t no;
//    uint8_t idx;
//    uint16_t x;
//    uint16_t y;
//}gui_assets_image_info_t; 

bool gui_image_assets_check_valid( void );

void gui_image_assets_get_merge_header( gui_asset_header_t* header); 


int gui_assets_get_image(uint32_t index, uint16_t no, gui_assets_image_t * image); 

static __GUI_INLINE void  gui_assets_get_image_offset( gui_assets_image_t *image, int offset);




GUI_RAM_CODE
static __GUI_INLINE void gui_assets_get_image_offset( gui_assets_image_t *image, int offset)
{
    image->address = image->address + offset * image->h * image->w * GUI_LCD_PIXEL_BYTES ;    
}


#if GUI_IS_SUPPORT_XIP > 0 
GUI_RAM_CODE
static void gui_assets_get_image_raw_value( uint32_t address, uint16_t *data, uint16_t size )
{
//    m_gui_hook.flash_load( address + GUI_PIC_RES_START_ADDRESS, (uint8_t*)data, size ); 
    memcpy( (uint8_t*)data, (uint8_t*)(address + GUI_PIC_RES_IMAGE_START_OFFSET), size); 
    
}
#else
void gui_assets_get_image_raw_value( uint32_t offset, uint16_t *data, uint16_t size ); 
#endif 

// #define GET_IMAGE_ADDR(x)       (uint16_t*)(x + GUI_PIC_RES_IMAGE_START_OFFSET) 

// #define GET_IMG_ADDR(x)         (x + GUI_PIC_RES_IMAGE_START_OFFSET) 


const char* gui_assets_get_hour_items(int i ); 
const char* gui_assets_get_minute_items(int i ); 

const char* iqw_gui_assets_get_year_items(int i );
const char* iqw_gui_assets_get_month_items(int i );
const char* iqw_gui_assets_get_day_items(int i );
#endif 

